<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>test二级菜单</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        ul {
            list-style: none;
        }

        ul.father {
            margin: 50px auto;
            width: 340px;
            height: 30px;
            background: url(./bg.jpg) no-repeat;
        }

        ul.father>li {
            float: left;
            margin-left: 10px;
            width: 100px;
            height: 30px;
            background: url(./libg.jpg) no-repeat;
            text-align: center;
            line-height: 30px;
        }

        ul.son {
            display: none;
        }

        ul.son>li {
            background: url(./libg.jpg) no-repeat;
        }
    </style>
</head>

<body>
    <ul class="father">
        <li>
            一级菜单
            <ul class="son">
                <li>二级菜单</li>
                <li>二级菜单</li>
                <li>二级菜单</li>
            </ul>
        </li>
        <li>
            一级菜单
            <ul class="son">
                <li>二级菜单</li>
                <li>二级菜单</li>
                <li>二级菜单</li>
            </ul>
        </li>
        <li>
            一级菜单
            <ul class="son">
                <li>二级菜单</li>
                <li>二级菜单</li>
                <li>二级菜单</li>
            </ul>
        </li>
    </ul>
</body>
<script>
    var fUlLis = document.querySelectorAll('.father>li')
    var sUls = document.querySelectorAll('ul.son')

    fUlLis.forEach((item, index) => {
        item.onmouseover = function () {
            sUls[index].style.display = 'block'
        }
        item.onmouseout = function () {
            sUls[index].style.display = 'none'
        }
    })
</script>

</html>